package com.gzzhsdcm.czh.myxw.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzzhsdcm.czh.myxw.R;
import com.gzzhsdcm.czh.myxw.getset.ShoyeGetset;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * @fileName ShoyeAdapter
 * @date on 2018-12-21 15:44
 * @company 贵州智合时代传媒有限公司
 * @developers czh
 * @email 1632365610@qq.com
 */
public class ShoyeAdapter extends BaseAdapter {
    Context context;
    List<ShoyeGetset.ResultBean.DataBean> list = new ArrayList<>();

    public ShoyeAdapter(Context context,List<ShoyeGetset.ResultBean.DataBean> list){
            this.context = context;
            this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyClass myClass;
        if (view==null){
            myClass = new MyClass();
            view = View.inflate(context, R.layout.itme_shoye,null);
            myClass.img1 =view.findViewById(R.id.img_img1);
            myClass.img2 =view.findViewById(R.id.img_img2);
            myClass.img3 =view.findViewById(R.id.img_img3);
            myClass.tvBt = view.findViewById(R.id.tv_shoye_bt);
            myClass.tvLm = view.findViewById(R.id.tv_lm);
            myClass.tvMs = view.findViewById(R.id.tv_shoye_ms);
            myClass.tvSj = view.findViewById(R.id.tv_shoye_sj);
            myClass.llTp = view.findViewById(R.id.ll_tp);
            view.setTag(myClass);
        }else {
            myClass = (MyClass) view.getTag();
        }
        myClass.tvSj.setText(list.get(i).getDate());
        myClass.tvMs.setText(list.get(i).getAuthor_name());
        myClass.tvBt.setText(list.get(i).getTitle());
        myClass.tvLm.setText(list.get(i).getCategory());
        if (list.get(i).getThumbnail_pic_s().isEmpty()){
            myClass.llTp.setVisibility(View.GONE);
        }else {
            Picasso.with(context)
                    .load(list.get(i).getThumbnail_pic_s())
                    .error(R.drawable.cw)
                    .fit()
                    .centerCrop()
                    .into(myClass.img1);
            Picasso.with(context)
                    .load(list.get(i).getThumbnail_pic_s02())
                    .error(R.drawable.cw)
                    .fit()
                    .centerCrop()
                    .into(myClass.img2);
            Picasso.with(context)
                    .load(list.get(i).getThumbnail_pic_s03())
                    .error(R.drawable.cw)
                    .fit()
                    .centerCrop()
                    .into(myClass.img3);
        }
        return view;
    }

    class MyClass{
        TextView tvBt,tvMs,tvSj,tvLm;
        ImageView img1,img2,img3;
        LinearLayout llTp;
    }
}
